package com.miniapp.service.impl;


import com.miniapp.entity.MiniProductEntity;
import com.miniapp.entity.MiniProductPriceEntity;
import com.miniapp.mapper.MiniProductMapper;
import com.miniapp.service.MiniProductPriceService;
import com.miniapp.service.MiniProductService;
import com.miniapp.utils.BaseUtils;
import com.miniapp.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;


@Service("miniProductService")
public class MiniProductServiceImpl extends BaseServiceImpl<MiniProductMapper,MiniProductEntity> implements MiniProductService {

    @Autowired
    MiniProductPriceService miniProductPriceService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public R removeByIdsNoPrice(List<Long> longs) {

        for (Long id :longs){
            List<MiniProductPriceEntity> priceEntities = miniProductPriceService.findByProductId(id);
            if (BaseUtils.isNotEmpty(priceEntities)&&priceEntities.size()>0){
                return R.error("请先删除版本套餐");
            }
        }
        this.removeByIds(longs);
        return R.ok("删除成功");
    }
}
